package lab03.test05;

import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;

public class Test05 {
    public static void main(String[] args) {
        //将字符串加密后，通过字符输出流写入文件，然后读取该文件并解密。
        // 加密算法为：将原有字符的 ASCII码加1，如'A'字符的 ASCII 码为65，
        // 加密后其 ASCII 码变成66。"	Hello"加密后的字符串为"Ifmmp"。

        File file = new File("D:\\旅院\\作业\\java\\1.txt");
        Scanner r = new Scanner(System.in);
        String s = r.nextLine();

        char b[] = s.toCharArray();
        for (int i = 0; i < b.length; i++) {
            if (b[i] >= 'A') {
                b[i] += 1;
            } else {
                b[i] -= 1;
            }
            FileWriter writer = null;
            FileReader reader = null;
            try {
                writer = new FileWriter("D:\\旅院\\作业\\java\\2.txt", true);
                writer.write(b);

                reader = new FileReader("D:\\旅院\\作业\\java\\1.txt");
                int n = 0;

                while ((n = reader.read(b, 0, 1)) != -1) {
                    String str = new String(b, 0, n);
                    char x[] = str.toCharArray();
                    if (x[0] <= 'c') {
                        System.out.println((char) (x[0] + 1));
                    } else {
                        System.out.println((char) (x[0] - 1));
                    }
                }
            } catch (IOException e) {
                e.printStackTrace();
            } finally {
                try {
                    writer.close();
                    reader.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }

    }
}
